package iostream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class TextImprove {
    // 将 D:\course\02-JavaSE进阶\day07-集合和泛型+数据结构和算法\
    // 复制到 D:\develop\idea\javase-code\day09-code\src\file\
    //
    public static void main2(String[] args) {
        //尝试使用自动关闭
        try (FileInputStream fis = new FileInputStream("day09-code/src/file/");
             FileOutputStream fos = new FileOutputStream("day09-code/src/iostream/")) {
            System.out.println("开始复制");
            long start = System.currentTimeMillis();
            byte[] car = new byte[1024];
            int len;
            while ((len = fis.read(car)) != -1){
                fos.write(car,0,len);
            }
            System.out.println("复制完毕");
            long end = System.currentTimeMillis();
             }
        catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            System.out.println("开始复制");
            long start = System.currentTimeMillis();
            fis = new FileInputStream("day09-code/src/file/072-面试题整理.avi");
            fos = new FileOutputStream("day09-code/src/file/1.avi");
            //定义一个字节数组
            byte[] car = new byte[1024];
            int len;//读取的字节数
            while ((len = fis.read(car)) != -1){
                fos.write(car,0,len);
            }

            System.out.println("复制完毕");
            long end = System.currentTimeMillis();
            System.out.println("耗时：" + (end - start) + "毫秒");
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
